Skip to content

导入定向用户协议号

创建快捷交易协议号上传任务,每个上传任务中需要上传一个快捷交易协议号文件。微信收到快捷交易协议号文件后,会识别出其中的微信用户,保存到指定的号码包中。一个号码包可以包含多个上传任务,这些上传任务导入的用户会被合并去重,再追加写到号码包。

请求参数类型描述
package_idstring号码包id
bodyobjectmultipart/form-data 数据结构
fileobject快捷交易协议号文件
metastring媒体文件元信息,使用json表示
bank_typestring银行类型
filenamestring文件名
sha256string文件的sha256摘要
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/active_user.csv');
$meta = \json_decode($media->getMeta());
$meta->bank_type = 'your_bank_id';
$media->setMeta(\json_encode($meta));

$instance->v3->marketing->bank->packages->_package_id_->tasks->postAsync([
  'package_id' => '8473295',
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/active_user.csv');
$meta = \json_decode($media->getMeta());
$meta->bank_type = 'your_bank_id';
$media->setMeta(\json_encode($meta));

$instance->chain('v3/marketing/bank/packages/{package_id}/tasks')->postAsync([
  'package_id' => '8473295',
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/active_user.csv');
$meta = \json_decode($media->getMeta());
$meta->bank_type = 'your_bank_id';
$media->setMeta(\json_encode($meta));

$instance['v3/marketing/bank/packages/{package_id}/tasks']->postAsync([
  'package_id' => '8473295',
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/active_user.csv');
$meta = \json_decode($media->getMeta());
$meta->bank_type = 'your_bank_id';
$media->setMeta(\json_encode($meta));

$response = $instance->v3->marketing->bank->packages->_package_id_->tasks->post([
  'package_id' => '8473295',
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/active_user.csv');
$meta = \json_decode($media->getMeta());
$meta->bank_type = 'your_bank_id';
$media->setMeta(\json_encode($meta));

$response = $instance->chain('v3/marketing/bank/packages/{package_id}/tasks')->post([
  'package_id' => '8473295',
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
php
$media = new \WeChatPay\Util\MediaUtil('file:///path/to/active_user.csv');
$meta = \json_decode($media->getMeta());
$meta->bank_type = 'your_bank_id';
$media->setMeta(\json_encode($meta));

$response = $instance['v3/marketing/bank/packages/{package_id}/tasks']->post([
  'package_id' => '8473295',
  'body' => $media->getStream(),
  'headers' => [
    'Content-Type' => $media->getContentType(),
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
返回字典类型描述
task_idstring上传任务
package_idstring号码包id
filenamestring文件名
bank_typestring银行类型
create_time string创建上传任务的时间
update_timestring上传任务最近一次更新的时间
statusstring任务状态
PROCESSING | FINISHED 枚举值之一
fail_countinteger失败数
success_countinteger成功数
success_user_countinteger匹配成功的微信用户数

参阅 官方文档

查询上传任务列表

查询号码包中符合条件的上传任务

请求参数类型描述
package_idstring号码包id
queryobject声明请求的查询参数
statusstring任务状态
PROCESSING | FINISHED 枚举值之一
filenamestring文件名
offsetinteger分页页码
limitinteger分页大小
php
$instance->v3->marketing->bank->packages->_package_id_->tasks->getAsync([
  'package_id' => '8473295',
  'query' => [
    'status' => 'PROCESSING',
    'filename' => 'active_user.csv',
    'offset' => 0,
    'limit' => 20,
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$instance->chain('v3/marketing/bank/packages/{package_id}/tasks')->getAsync([
  'package_id' => '8473295',
  'query' => [
    'status' => 'PROCESSING',
    'filename' => 'active_user.csv',
    'offset' => 0,
    'limit' => 20,
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$instance['v3/marketing/bank/packages/{package_id}/tasks']->getAsync([
  'package_id' => '8473295',
  'query' => [
    'status' => 'PROCESSING',
    'filename' => 'active_user.csv',
    'offset' => 0,
    'limit' => 20,
  ],
])
->then(static function(\Psr\Http\Message\ResponseInterface $response) {
  print_r(json_decode((string) $response->getBody(), true));
})
->wait();
php
$response = $instance->v3->marketing->bank->packages->_package_id_->tasks->get([
  'package_id' => '8473295',
  'query' => [
    'status' => 'PROCESSING',
    'filename' => 'active_user.csv',
    'offset' => 0,
    'limit' => 20,
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
php
$response = $instance->chain('v3/marketing/bank/packages/{package_id}/tasks')->get([
  'package_id' => '8473295',
  'query' => [
    'status' => 'PROCESSING',
    'filename' => 'active_user.csv',
    'offset' => 0,
    'limit' => 20,
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
php
$response = $instance['v3/marketing/bank/packages/{package_id}/tasks']->get([
  'package_id' => '8473295',
  'query' => [
    'status' => 'PROCESSING',
    'filename' => 'active_user.csv',
    'offset' => 0,
    'limit' => 20,
  ],
]);
print_r(json_decode((string) $response->getBody(), true));
返回字典类型描述
total_countinteger总数量
offsetinteger分页页码
limitinteger分页大小
dataobject[]上传任务列表
task_idstring上传任务
package_idstring号码包id
filenamestring文件名
bank_typestring银行类型
create_timestring创建上传任务的时间
update_timestring上传任务最近一次更新的时间
statusstring任务状态
PROCESSING | FINISHED 枚举值之一
success_countinteger成功数
fail_countinteger失败数
success_user_countinteger匹配成功的微信用户数

参阅 官方文档

Published on the GitHub by TheNorthMemory